package com.ruoyi.household.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.BuildingSystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.household.service.IBuildingSystemService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 楼栋CRUDController
 * 
 * @author ruoyi
 * @date 2022-10-01
 */
@RestController
@RequestMapping("/building")
public class BuildingSystemController extends BaseController
{
    @Autowired
    private IBuildingSystemService buildingSystemService;

    /**
     * 查询楼栋CRUD列表
     */
    @RequiresPermissions("building:building:list")
    @GetMapping("/list")
    public TableDataInfo list(BuildingSystem buildingSystem)
    {
        startPage();
        List<BuildingSystem> list = buildingSystemService.selectBuildingSystemList(buildingSystem);
        return getDataTable(list);
    }

    /**
     * 导出楼栋CRUD列表
     */
    @RequiresPermissions("building:building:export")
    @Log(title = "楼栋CRUD", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuildingSystem buildingSystem)
    {
        List<BuildingSystem> list = buildingSystemService.selectBuildingSystemList(buildingSystem);
        ExcelUtil<BuildingSystem> util = new ExcelUtil<BuildingSystem>(BuildingSystem.class);
        util.exportExcel(response, list, "楼栋CRUD数据");
    }

    /**
     * 获取楼栋CRUD详细信息
     */
    @RequiresPermissions("building:building:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(buildingSystemService.selectBuildingSystemById(id));
    }

    /**
     * 新增楼栋CRUD
     */
    @RequiresPermissions("building:building:add")
    @Log(title = "楼栋CRUD", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuildingSystem buildingSystem)
    {
        return toAjax(buildingSystemService.insertBuildingSystem(buildingSystem));
    }

    /**
     * 修改楼栋CRUD
     */
    @RequiresPermissions("building:building:edit")
    @Log(title = "楼栋CRUD", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuildingSystem buildingSystem)
    {
        return toAjax(buildingSystemService.updateBuildingSystem(buildingSystem));
    }

    /**
     * 删除楼栋CRUD
     */
    @RequiresPermissions("building:building:remove")
    @Log(title = "楼栋CRUD", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buildingSystemService.deleteBuildingSystemByIds(ids));
    }
}
